package com.heubu.mall.controller;

import com.github.pagehelper.PageInfo;
import com.heubu.mall.service.IProductService;
import com.heubu.mall.vo.ProductDetailVo;
import com.heubu.mall.vo.ResponseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Wangchuang
 * @Date: 2022/5/6 12:40
 * @Version 1.0
 * @Description:
 */
@Slf4j
@RestController
public class ProductController {
    
    @Autowired
    private IProductService productService;
    
    @GetMapping("/products")
    public ResponseVo<PageInfo> list(@RequestParam(required = false) Integer categoryId,
                                     @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                     @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return productService.list(categoryId, pageNum, pageSize);
    }
    
    @GetMapping("/products/{productId}")
    public ResponseVo<ProductDetailVo> detail(@PathVariable Integer productId) {
        return productService.detail(productId);
    }
}
